package com.atg.atgchat.init.user.dao;

import com.atg.atgchat.init.user.mapper.UserMapper;
import com.atg.atgchat.init.user.model.entity.User;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/*
author: atg
time: 2025/1/14 10:54
*/
@Service
public class UserDao extends ServiceImpl<UserMapper, User> {
    public User getByOpenId(String openId) {
        User userOne = lambdaQuery().eq(User::getOpenId, openId).one();
        return userOne;
    }

    public Boolean existsByUsername(String username) {
        // 修改: 添加 count() 方法调用
        return lambdaQuery().eq(User::getName, username).count() > 0;
    }
    // 获取用户名
    public User getUserName(String name) {
        User user =  lambdaQuery().eq(User::getName, name).one();
        return user;
    }

    public void modifyName(Long uid, String name) {
        User update = new User();
        update.setId(uid);
        update.setName(name);
        updateById(update);
    }

    public void wearingBadge(Long uid, Long badgeId) {
        User update = new User();
        update.setId(uid);
        update.setItemId(badgeId);
        updateById(update);
    }
}